package com.five.monkey.feign.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.five.monkey.enums.StatusEnum;
import com.five.monkey.feign.provider.convert.UserConvert;
import com.five.monkey.feign.provider.dao.mapper.UserMapper;
import com.five.monkey.feign.provider.dao.model.UserModel;
import com.five.monkey.feign.provider.service.UserService;
import com.five.monkey.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 狻猊
 * @date 2021/8/10 下午5:20
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserVo login(String name, String password) {
        LambdaQueryWrapper<UserModel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserModel::getName, name);
        lambdaQueryWrapper.eq(UserModel::getPassword, password);
        lambdaQueryWrapper.eq(UserModel::getStatus, StatusEnum.valid.getStatus());
        return UserConvert.model2vo(userMapper.selectOne(lambdaQueryWrapper));
    }

    @Override
    public UserVo findById(Long id) {
        LambdaQueryWrapper<UserModel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserModel::getId, id).eq(UserModel::getStatus, StatusEnum.valid.getStatus());
        return UserConvert.model2vo(userMapper.selectOne(lambdaQueryWrapper));
    }
}
